# =============================================================================
if (OS_WINDOWS)
  set(LIBUSB_ROOT ${COMMON_THIRD_LIB}/libusb)

  find_library(LIBUSB_LIBRARY_DEBUG
    NAMES libusb-1.0
    PATHS ${LIBUSB_ROOT}/x64/Debug
    PATH_SUFFIXES "lib" "lib32" "lib64"
    REQUIRED)
  find_library(LIBUSB_LIBRARY_RELEASE
    NAMES libusb-1.0
    PATHS ${LIBUSB_ROOT}/x64/Release
    PATH_SUFFIXES "lib" "lib32" "lib64"
    REQUIRED)
elseif(OS_LINUX)
  find_package(PkgConfig)
  pkg_check_modules(libusb-1.0 REQUIRED libusb-1.0)
endif()

macro(use_libusb ag_project_name)
  target_compile_definitions(${ag_project_name} PRIVATE USE_LIB_LIBUSB)

  if (OS_WINDOWS)
    target_include_directories(${ag_project_name} PRIVATE ${LIBUSB_ROOT}/libusb)
    target_link_libraries(${ag_project_name} PRIVATE 
      debug ${LIBUSB_LIBRARY_DEBUG}
      optimized ${LIBUSB_LIBRARY_RELEASE})
  elseif(OS_LINUX)
    target_include_directories(${ag_project_name} PRIVATE ${libusb-1.0_INCLUDE_DIRS})
    target_link_libraries(${ag_project_name} PRIVATE ${libusb-1.0_LIBRARIES})
  endif()
endmacro(use_libusb)